// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import O1HD, { managers } from "../../../engines/gameEngine";
import NormalLevelBase from "../../../Game/Base/LevelBase";
import { PAGE } from "../../../Game/Enum";
import { IWinPagePrams } from "../../../Game/Interface";
import mainRoot from "../../../Game/MainRoot";


const {ccclass, property} = cc._decorator;

@ccclass
export default class Level_InputReply extends NormalLevelBase {

    protected Reply:string[]=['这个就叫专业','不愧是职场精英','情商高了','要不你来当老板吧']


    @property({type:cc.EditBox,displayName:"输入框"})
    private InputEditor:cc.EditBox=null;

    @property({type:cc.Label,displayName:'显示label'})
    private ShowLabel:cc.Label=null;
    init(): void {

    }

    OnBtnConfim()
    {
        if(this.InputEditor.textLabel.string=='')
        {

            return
        }
        this.Win(1)
    }

    OnBtnInput()
    {
        this.InputEditor.node.height = 0.1;
        this.InputEditor.focus();
    }

    protected update(dt: number): void {
        if(this.InputEditor.textLabel.string!=this.ShowLabel.string)
        {
            console.warn(this.InputEditor.textLabel.string,"????")
            this.ShowLabel.string=this.InputEditor.textLabel.string
        }
    }
    Win(time?:number) {
        if (this.hadEnd) { return; }
        this.hadEnd = true;

        // this.ShowObj("Xz_Zq", (node: cc.Node) => {
            //     // managers().soundMgr.playSound("huaquan");
            //     node.setPosition(position);
            // });
        mainRoot.UISystem.ClosePage(PAGE.TIPSPAGE);
        let delayTime:number = 3.5;
        if(time){
            delayTime = time;
        }
        this.scheduleOnce(async () => {
            managers().soundMgr.playSound('mainSound/win');
            const show=this.Reply[Math.floor(Math.random()*this.Reply.length)];
            let winPrams: IWinPagePrams = {
                mode: this.m_mode,
                winText: show,
                index: this.levelInfo.level
            };
            await mainRoot.UISystem.OpenPage(PAGE.WINPAGE, winPrams);
            mainRoot.LevelSystem.AddLevel(this.m_mode);
            console.warn('重置6');
            mainRoot.GotTips = false;
            mainRoot.GotAnswer = false;
        }, delayTime);
    }
    // update (dt) {}
}
